<?php

namespace app\admin\model;

use think\Model;

/**
 * Orders
 */
class Orders extends Model
{
    // 表名
    protected $name = 'orders';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 字段类型转换
    protected $type = [
        'paid_time' => 'timestamp:Y-m-d H:i:s',
    ];
    protected  $append = [
        'pay_status_text',
        'check_text'
    ];

    public function getCheckTextAttr($value,$data)
    {
        $check_status = $data['check_status'];
        $check_text = '';
        switch ($check_status) {
            case 0:
                $check_text = '待提现';
                break;
            case 1:
                $check_text = '待审核';
                break;
            case 2:
                $check_text = '已打款';
                break;
            case 3:
                $check_text = '已驳回';
                break;
            default:
                $check_text = '未知';
                break;
        }
        return $check_text;
    }


    public function getOrderAmountAttr($value): float
    {
        return (float)$value;
    }

    public function getPayStatusTextAttr($value,$data)
    {
        $pay_status = $data['pay_status'];
        $pay_status_text = '';
        //0=待支付,1=支付成功,2=已退款
        switch ($pay_status) {
            case 0:
                $pay_status_text = '待支付';
                break;
            case 1:
                $pay_status_text = '支付成功';
                break;
            case 2:
                $pay_status_text = '已退款';
                break;
            default:
                $pay_status_text = '未知';
                break;
        }
        return $pay_status_text;
    }
    public function user(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\User::class, 'user_id', 'id');
    }

}
